<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Springboot集成thymeleaf模板引擎</title>
</head>
<body>
    <h1 th:text="${Host}">Hello thymeleaf </h1>
    <h1 >Hello thymeleaf </h1>
    <p> Spring Boot默认提供静态资源目录位置需置于classpath下，目录名需符合如下规则：<br/>
        /static<br/>
        /public<br/>
        /resources<br/>
        /META-INF/resources</p>

    <p>
        举例：我们可以在src/main/resources/目录下创建static，在该位置放置一个图片文件。
        启动程序后，尝试访问http://localhost:8080/D.jpg。如能显示图片，配置成功。
    </p>



    <li th:each="book : ${bookList}" th:text="${book.title}">En las Orillas del Sar</li>



    <table class="table">
        <thead>
        <th th:each="userhead : ${userhead}" th:text="${userhead.key}"></th>
        <th th:each="userhead : ${userhead}" th:text="${userhead.value}"></th>
        </thead>
        <tbody >
        <td th:each="userinfo:${userinfo}" th:text="${userinfo}"></td>
        <td th:each="bookinfo:${books}" th:text="${bookinfo.title}"></td>
        </tbody>
    </table>
    <ul>
        <li th:each="book:${books}" th:text="${book.title}" ></li>
        <li th:each="book:${books}" th:text="${book.cost}"></li>
        <li th:each="book:${books}" th:text="${book.publisher}"></li>
    </ul>

    <ul th:each="lm : ${listmap}">
        <li th:each="entry : ${lm}" th:text="${entry.key}" ></li>
        <li th:each="entry : ${lm}" th:text="${entry.value}"></li>
    </ul>


    <p th:text="'Hello！:, ' + ${person.name} + '!' + '----' + ${person.age} + '----'+ ${person.sex}" ></p>
    <br/><br/>


    <div>
        <p>input中的value</p>
        <input type="text" th:value="${person.name}"/>
        <br/><br/>


        <p>运算符:</p>
        <p th:with="isEven=(3 % 2 == 0)"></p>
        <br/><br/>


        <p>条件判断 是否为空</p>
        <div th:if="${not #lists.isEmpty(persons)}">
            <p>循环遍历</p>
            <div th:each="person:${persons}">
                <p style="background:olive;color:white;">
                    <span th:text="${person.name}"></span>--<span th:text="${person.age}"></span>
                    <span th:text="${person.sex}"></span>
                </p>
            </div>
        </div>
        <br/><br/>


        <p>switch</p>
        <div>
            <div th:switch="${person.name}">
                <p th:case="'曹雪坤'">曹雪坤</p>
                <p th:case="#{person.age}">钟亮</p>
                <p th:case="*">孙正强</p>
            </div>
        </div>
        <br/><br/>

        <p>if</p>
        <p th:if="${person.age == '11'}">满足条件才显示</p>
        <br/><br/>

        <p>unless</p>
        <p th:unless="${person.age == '12'}">不满足条件才显示</p>
        <br/><br/>

        <!-- <p>判断符号用法：gt(>), lt(<), ge(>=), le(<=), not(!). Also eq(==), neq/ne (!=)</p> -->
        <p>gt(&gt;), lt(&lt;)</p>
        <p th:if="11 &lt; 12">&lt;</p>
        <br/><br/>



    </div>
    <!-- js获取model中的值 -->
    <script th:inline="javascript">
        var name = [[${person.name}]];
        alert(name);
    </script>

    <br/>
    <h1>内置对象的使用</h1>

    <p  th:text = "${#dates.createNow()}"></p>

    <p>
    为了模板更加易用，Thymeleaf还提供了一系列Utility对象（内置于Context中），可以通过#直接访问：

    #dates
    #calendars
    #numbers
    #strings
    arrays
    lists
    sets
    maps
    ...

        <span> 日期</span><br/>



    ${#dates.format(date, 'dd/MMM/yyyy HH:mm')}<br/>
    ${#dates.arrayFormat(datesArray, 'dd/MMM/yyyy HH:mm')}<br/>
    ${#dates.listFormat(datesList, 'dd/MMM/yyyy HH:mm')}<br/>
    ${#dates.setFormat(datesSet, 'dd/MMM/yyyy HH:mm')}<br/>


        /*
        * Create a date (java.util.Date) object for the current date and time
        */
        ${#dates.createNow()}

        /*
        * Create a date (java.util.Date) object for the current date (time set to 00:00)
        */
        ${#dates.createToday()}

    </p>


    /*
    * Check whether a String is empty (or null). Performs a trim() operation before check
    * Also works with arrays, lists or sets
    */
    ${#strings.isEmpty(name)}
    ${#strings.arrayIsEmpty(nameArr)}
    ${#strings.listIsEmpty(nameList)}
    ${#strings.setIsEmpty(nameSet)}

    /*
    * Check whether a String starts or ends with a fragment
    * Also works with arrays, lists or sets
    */
    ${#strings.startsWith(name,'Don')}                  // also array*, list* and set*
    ${#strings.endsWith(name,endingFragment)}           // also array*, list* and set*

    /*
    * Compute length
    * Also works with arrays, lists or sets
    */
    ${#strings.length(str)}

    /*
    * Null-safe comparison and concatenation
    */
    ${#strings.equals(str)}
    ${#strings.equalsIgnoreCase(str)}
    ${#strings.concat(str)}
    ${#strings.concatReplaceNulls(str)}

    /*
    * Random
    */
    ${#strings.randomAlphanumeric(count)}

    <!--
       <p  th:each="${book}"  >
           <li th:text="*{title}"></li>

       </p>

       <tbody th:remove="all-but-first">　　　　　　　　　　
           <tr th:each="product:${productList}">　　　　　　　　　　　　
               <td th:text="${productStat.count}">1</td>
               <td th:text="${product.description}">Red Chair</td>
               <td th:text="${'$' + #numbers.formatDecimal(product.price, 1, 2)}">$123</td>
               <td th:text="${#dates.format(product.availableFrom, 'yyyy-MM-dd')}">2014-12-01</td>
           </tr>
           <tr>
               <td>White table</td>
               <td>$200</td>
               <td>15-Jul-2013</td>
           </tr>
           <tr>
               <td>Reb table</td>
               <td>$200</td>
               <td>15-Jul-2013</td>
           </tr>
           <tr>
               <td>Blue table</td>
               <td>$200</td>
               <td>15-Jul-2013</td>
           </tr>
       </tbody>
       -->
</body>
</html>